//package com.qijian.plug.capacity.cost;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.qijian.finance.domain.Cost;
//import com.qijian.finance.domain.enums.CostTypeEnum;
//import com.qijian.finance.service.ICostService;
//import com.qijian.plug.AbstractPlug;
//import org.apache.commons.collections4.CollectionUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//import java.util.Map;
//import java.util.Set;
//
///**
// * 成本计算器
// */
//@Component
//public abstract class CostPlugWrapper<T> implements AbstractPlug {
//
//    protected ICostService costService;
//
//    @Autowired
//    public void setCostService(ICostService costService) {
//        this.costService = costService;
//    }
//
//    protected abstract void operation(List<Object> args);
//
//    protected boolean condition(List<Object> args) {
//        return true;
//    }
//
//    @Override
//    public void doSomething(List<Object> args) {
//        if (condition(args))
//            operation(args);
//    }
//
////    protected Cost initTopCost(String projectMachineNo) {
////        Cost temp = new Cost();
////        temp.setId(IdUtils.singletonSnowId());
////        temp.setElement(projectMachineNo);
////        temp.setTopId(temp.getId());
////        temp.setParentId(0L);
////        temp.setHighId(0L);
////        temp.setActualCost(BigDecimal.ZERO);
////        temp.setBudgetCost(BigDecimal.ZERO);
//////        temp.setYearMonth(DateUtils.dateTimeNow(DatePattern.NORM_MONTH_PATTERN));
////        fillProjectMachine(temp);
////        return temp;
////    }
//
////    protected Cost initHighCost(Cost top, String projectMachineNo, CostTypeEnum costType) {
////        Cost temp = new Cost();
////        temp.setId(IdUtils.singletonSnowId());
////        temp.setCostType(costType.getVal());
////        temp.setProjectId(top.getProjectId());
////        temp.setElement(projectMachineNo);
////        temp.setTopId(top.getTopId());
////        temp.setHighId(temp.getId());
////        temp.setParentId(top.getId());
////        temp.setActualCost(BigDecimal.ZERO);
////        temp.setBudgetCost(BigDecimal.ZERO);
//////        temp.setYearMonth(DateUtils.dateTimeNow(DatePattern.NORM_MONTH_PATTERN));
////        fillProjectMachine(temp);
////        return temp;
////    }
//
////    protected Cost initChildCost(Cost parent, String projectMachineNo, String costType) {
////        Cost temp = new Cost();
////        temp.setId(IdUtils.singletonSnowId());
////        temp.setCostType(costType == null ? "null" : costType);
////        temp.setProjectId(parent.getProjectId());
////        temp.setElement(projectMachineNo);
////        temp.setTopId(parent.getTopId());
////        temp.setHighId(parent.getHighId());
////        temp.setParentId(parent.getId());
////        temp.setActualCost(BigDecimal.ZERO);
////        temp.setBudgetCost(BigDecimal.ZERO);
//////        temp.setYearMonth(DateUtils.dateTimeNow(DatePattern.NORM_MONTH_PATTERN));
////        fillProjectMachine(temp);
////        return temp;
////    }
//
////    private void fillProjectMachine(Cost c) {
////        String[] pm = splitProjectMachineNo(c.getElement());
////        if (pm != null && pm.length == 2) {
////            c.setProjectNo(pm[0]);
////            c.setMachineNo(pm[1]);
////        }
////    }
//
//
//    protected void saveOrUpdateBatch(List<Cost> data) {
//        if (CollectionUtils.isNotEmpty(data))
//            costService.saveOrUpdateBatch(data);
//    }
//
//    protected void updateYearMonth(Set<String> elements, String yearMonth) {
//        if (CollectionUtils.isEmpty(elements))
//            return;
//        Cost c = new Cost();
//        c.setYearMonth(yearMonth);
//        QueryWrapper<Cost> wrapper = new QueryWrapper<>();
//        wrapper.in("element", elements);
//        costService.update(c, wrapper);
//    }
//
////
////    protected String[] splitProjectMachineNo(String projectMachineNo) {
////        if (projectMachineNo == null)
////            return null;
////        String projectNo = StringUtils.substringBefore(projectMachineNo, "(");
////        String machineNo = StringUtils.substringBetween(projectMachineNo, "(", "#)");
////        return new String[]{projectNo, machineNo};
////    }
//
//    protected Cost getChildCost(Map<String, Cost> data, String element, String costType, Cost parent) {
//        String uniqueKey = costService.generateUniqueKey(element, costType, parent.getId());
//        if (!data.containsKey(uniqueKey)) {
//            data.put(uniqueKey, Cost.initChildCost(parent, element, costType));
//        }
//        return data.get(uniqueKey);
//    }
//
//    protected Cost getHighCost(Map<String, Cost> data, String element, CostTypeEnum costType, Cost top) {
//        String uniqueKey = costService.generateUniqueKey(element, costType.getVal(), top.getId());
//        if (!data.containsKey(uniqueKey)) {
//            data.put(uniqueKey, Cost.initHighCost(top, element, costType));
//        }
//        return data.get(uniqueKey);
//    }
//
//    protected Cost getTopCost(Map<String, Cost> data, String element) {
//        if (!data.containsKey(element)) {
//            data.put(element, Cost.initTopCost(element));
//        }
//        return data.get(element);
//    }
//
//}
